﻿using SF.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SF.Ucenter.mycenterusers
{
    public partial class newpay : System.Web.UI.Page
    {
        BLL.sf_user_bank bll = new BLL.sf_user_bank();
        Model.sf_user_info userInfo;
        string appWhere;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                /*验证用户是否登录*/
                if (Session[DTKeys.SESSION_ADMIN_INFO] == null)
                {
                    Response.Redirect("index.aspx");
                }
            }
        }
        /// <summary>
        /// 添加地址
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                userInfo = Session[DTKeys.SESSION_ADMIN_INFO] as Model.sf_user_info;
                appWhere = Utils.getWhereByInfo(userInfo.busnieseNum, userInfo.appNum, userInfo.templatesNum);
                if (mobile.Value != "" && name.Value != "" && card.Value != "")
                {
                    Model.sf_user_bank model = new Model.sf_user_bank();
                    model.userNum = userInfo.userNum;
                    model.busnieseNum = userInfo.busnieseNum;
                    model.appNum = userInfo.appNum;
                    model.templatesNum = userInfo.templatesNum;
                    do
                    {
                        model.bankNum = Utils.GetCheckCode(6);
                    } while (bll.ExistsByNum(model.bankNum,userInfo.userNum,appWhere));
                    if (rblStatus_0.Checked)
                        model.cardTypes = 1;
                    else if (rblStatus_1.Checked)
                        model.cardTypes = 2;
                    else if (rblStatus_2.Checked)
                        model.cardTypes = 3;
                    model.personName = name.Value.Trim();
                    model.bankNumber = card.Value.Trim();
                    model.bankName = "";
                    model.phone = mobile.Value.Trim();
                    bll.Add(model);
                    Response.Redirect("payway.aspx");
                }
                else
                {
                    Response.Write("<script>alert('请完善信息!');</script>");
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}